package lagou.homework.lagou_homework_rocketmq.service.impl;

import lagou.homework.lagou_homework_rocketmq.entity.Order;
import lagou.homework.lagou_homework_rocketmq.repository.GoodsRepository;
import lagou.homework.lagou_homework_rocketmq.repository.OrderRepository;
import lagou.homework.lagou_homework_rocketmq.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private OrderRepository orderRepository;
    @Autowired
    private GoodsRepository goodsRepository;

    @Override
    @Transactional
    public void decreaseStock(String orderNo, int buyNum){
        Order order = orderRepository.findByOrderNo(orderNo);
        Integer goodsId = order.getGoodsId();
        goodsRepository.decreaseStock(goodsId,buyNum);
    }

    @Override
    @Transactional
    public void increaseStock(String orderNo, int buyNum){
        Order order = orderRepository.findByOrderNo(orderNo);
        Integer goodsId = order.getGoodsId();
        goodsRepository.increaseStock(goodsId,buyNum);
    }


}
